interface heroResponse<T> {
  code: number
  msg: string
  data: T
}
interface heroItem {
  heroId: number
  name: string
  alias: string
  title: string
  roles: string[]
  isWeekFree: string
  attack: string
  defense: string
  magic: string
  difficulty: string
  selectAudio: string
  banAudio: string
  isARAMweekfree: string
  ispermanentweekfree: string
  changeLabel: string
  goldPrice: string
  couponPrice: string
  camp: string
  campId: string
  keywords: string
  icon: string
}
interface hero {
  // name: string
  heroId: number
  title: string
  icon: string
}


Page({
  data: {
    heroList: [] as hero[],
    value: ''
  },
  onLoad() {
    this.getData()
  },
  getData(name?: string) {
    wx.showLoading({ title: '数据加载中...' })
    wx.request<heroResponse<hero[]>>({
      url: 'https://api-vue-base.itheima.net/api/lol/search',
      method: 'GET',
      data: {
        q: name || ''
      },
      success: (res) => {
        wx.hideLoading()
        console.log(res)
        this.setData({
          heroList: res.data.data
        })
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },
  search() {
    this.getData(this.data.value)
  },
})